#include "OgreManager.h"
#include "../res/resource.h"

IOgreManager* OgreManager::_ogreManager;

OgreManager::OgreManager() : _window(NULL), _sceneMgr(NULL), _camera(NULL){

#ifdef _DEBUG
    _resourcesConfig = "resources_d.cfg";
    _pluginsConfig = "plugins_d.cfg";
#else
    _resourcesConfig = "resources.cfg";
    _pluginsConfig = "plugins.cfg";
#endif
}

void OgreManager::Initialize(){
	_root = new Ogre::Root(_pluginsConfig);

	 if(!_root->showConfigDialog()){
		 GameServices::GameEngine()->ShutDown();
		 return;
	 }
    
	_window = _root->initialise(true, "GameEngine Render Window");
	 _sceneMgr = _root->createSceneManager(Ogre::ST_GENERIC, "DefaultScene");
	_camera = _sceneMgr->createCamera("DefaultCamera");

	_window->addViewport(_camera);


	//Create a new log specifically for the project
	Ogre::LogManager::getSingleton().createLog("Dlog.txt");
}

void OgreManager::UpdateStarted(const Ogre::FrameEvent& gameTime){}
void OgreManager::UpdateEnded(const Ogre::FrameEvent& gameTime){}

void OgreManager::Cleanup(){
	if(_window){
		_window->removeAllViewports();
		_window->destroy();
	}
	if(_camera)
		_sceneMgr->destroyCamera(_camera);
	
	if(_sceneMgr)
		_root->destroySceneManager(_sceneMgr);
	
	delete _root;
}